#ifndef REQUESHANDLER_H
#define REQUESTHANDLER_H

#include "DatabaseManager.h"
#include <json/json.h>
#include <string>
#include <iostream>
 
using namespace std;


class  RequestHandler
{
public:
    enum Operation
    {
        ADD_ACCOUNT,   //添加数据
        DELETE_ACCOUNT,  //删除数据
        UPDATE_ACCOUNT,  //更新数据
        QUERY_ACCOUNT,    //请求数据
        LOGIN_ACCOUNT, //登陆
        UNKNOWN    //未知操作
    };
    static RequestHandler& getInstance()
    {
        static RequestHandler instance;
        return instance;
    }
    string handleRequest(const string & request);
   
    ~ RequestHandler() = default;
    Operation parseOperation(const string& opStr);  //解析是哪种操作
private:
    Json::Value addAccount(const Json::Value& data);
    Json::Value deleteAccount(const Json::Value& data);
    Json::Value updateAccount(const Json::Value& data);
    Json::Value queryAccount(const Json::Value& data);
    Json::Value loginAccount(const Json::Value& data);
private:
    DatabaseManager& m_dbManager = DatabaseManager::getInstance();
    RequestHandler();
};


#endif
 

